package com.atguigu.lease.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonFormat;

/*
能将响应结果像正常java对象一样转换为JSON
      "type": {
        "code": 1,
        "name": "公寓"
      },
      而不是:
      "type": "APARTMENT",
      或:
      "type": "1",
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
*/
public enum ItemType implements BaseEnum {

    APARTMENT(1, "公寓"),

    ROOM(2, "房间");

    //@EnumValue: 能将Integer等类型转成当前枚举类型对象
    @EnumValue
    //@JsonValue: 响应时将枚举对象名(APARTMENT/ROOM)转成code值(1/2)
    @JsonValue
    private Integer code;
    private String name;

    @Override
    public Integer getCode() {
        return this.code;
    }


    @Override
    public String getName() {
        return name;
    }

    ItemType(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

}
